home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////////////
- // Package node class header file
- // Copyright (c) 1991 by Azarona Software
- // All rights reserved.
- ////////////////////////////////////////////////////////////
-
- #ifndef H_PNODE
- #define H_PNODE
-
- // We use our own custom allocator for pnodes, cause
- // it's much faster and takes less memory than using
- // Turbo C++'s generic new and delete routines
-
- struct anode { // allocator node for pnodes
- int node_cnt; // sizeof(node_cnt) + sizeof(pnode_data)
- int pnode_data[5]; // must >= sizeof(pnode)
- unsigned n; // Pointer to next pnode on free list
- };
-
- struct pnode_allocator {
- anode *data;
- int size;
- pnode_allocator(int sz);
- ~pnode_allocator(void) { delete[size] data; }
- void *alloc(void);
- void free(void *p);
- int room(void) { return size - data->node_cnt; }
- };
-
- // Package node class. Note how new() and delete()
- // are overloaded
-
- struct pnode { // package node
- long wt; // weight of the node
- pnode *n; // to other members in the package
- unsigned char sym; // which symbol this node is for
- signed char lvl; // what level that symbol is at (-1 means internal)
- static pnode_allocator *pal;
- pnode(long w, unsigned char s, signed char l, pnode *nx) {
- wt = w; sym = s; lvl = l; n = nx;
- }
- void *operator new(size_t) { return (void *)pal->alloc(); }
- void operator delete(void *p) { pal->free(p); }
- static pnode *make_package(pnode *a, pnode *b);
- static void rmv_package(pnode *p);
- };
-
- // Set of package nodes, represented as an array of pointers
-
- struct nodeset {
- pnode **data;
- int sz, cursor;
- nodeset(int ns) { data = new pnode*[sz = ns*2]; cursor = 0; }
- ~nodeset(void) { delete[sz] data; }
- pnode *remove_front(void);
- void package(void);
- void setup_and_merge(nodeset &nset, long wts[], unsigned char smap[],
- int num_syms, int level);
- int isempty(void) { return cursor == 0; }
- };
-
- #endif
-
-